#ifndef VSCINTILLAEX_H
#define VSCINTILLAEX_H

#include <QWidget>
#include <QMap>
#include <QString>
#include <QMenu>
#include <QTimer>
#include "VScintillaBase.h"
#include "VQscilexerCppAttach.h"
#include "VWords.h"

class VScintillaEx : public VScintillaBase
{
    Q_OBJECT
public:
    explicit VScintillaEx(QWidget *parent = 0);
    VScintillaEx(QWidget *parent, QString path, QString text, int type);

    enum HIDE
    {
        ALL,
        PARAMETER,
        INPUT,
        MOUSE
    };

    struct StyleData{
        int fore;
        int back;
        bool bold;
        bool italic;
    };
    QMap<QString, StyleData> _style_map;
    QString _path;
    bool _modify;
    int _type;
    QMenu _content_menu;
    QMenu _expand_menu;

    void save();
	void reload();
	void no_reload();
    bool save_question();
    void jump_request();
    void input_word(VWords* ptr);
    void append_navigation();
    void modify_testing();
    void reload_setting();
    void update_text();
    void rename(QString path);
	bool is_last_time_changed();

signals:
    void signal_hide_tip(int mode);
    void signal_inpout_tip(QString path, QString text, int line, bool in);
    void signal_function_parameter_tip(QString path, QString name, int cursor_pos, int parameter_pos);
    void signal_mouse_hover_tip(QString path, QString before, QString after, int line, bool in, int pos);
    void signal_file_tip(QString path, QString text);
//    void signal_modificationChanged(QString path, bool m);
    void signal_save_file(QString path, QString text, int type, uint last);
    void signal_update_file_text(QString path, QString text);
    void signal_update_file_last_modify_time(QString path, uint time);
    void signal_reload_file(QString path);
    void signal_select_word(QString path, VWords* word);
    void signal_jump_request(QString path, QString pre, QString next, int line_number, bool in_function);
    void signal_append_navigation(QString path, int line, int pos);
    void signal_set_title(QString path, QString title);
    void signal_scintilla_update_info(QString path, int line, int pos, int lines);

public slots:

private:
    VQscilexerCppAttach _vlexer;
    uint _last_modify_time;
    QTimer _tip_timer;
    QTimer _update_timer;
	QMap <int, QString> _symbol;

    void init_menu();
    void init_setting();
    void init_color();
    void init_option();
    void init_connect();
    void auto_indentation();

    void symbol_complate(int c);
    bool symbol_delete(int c);
    bool in_function(int line);
    QString get_line_text_of_pos_before(int pos);
    QString get_line_text_of_pos_next(int pos);
    QString input_block(int pos);
    void function_parameter_tip();
    bool is_input_file_name(QString text);
    int get_char_count(QString text, QChar c);
    void input_tip_testing();
    QString reget_string(QString text, QString ex);
    void set_modify(bool m);
    QString get_input_block();
	void init_symbol();

    void contextMenuEvent(QContextMenuEvent *);
    bool eventFilter(QObject *watched, QEvent *event);

private slots:
    void on_marginClicked(int margin, int line);
    void on_SCN_UPDATEUI(int updated);
    void on_SCN_ZOOM();
    void on_linesChanged();
    void on_selectionChanged();
    void on_SCN_NEEDSHOWN(int i1, int i2);
    void on_SCN_HOTSPOTCLICK(int position, int modifiers);
    void on_SCN_CHARADDED(int charadded);
    void on_modificationChanged(bool m);
    void on_SCN_DWELLEND(int position, int x, int y);
    void on_SCN_DWELLSTART(int position, int x, int y);
    void on_SCN_FOCUSOUT();
    void on_SCN_FOCUSIN();
    void on_tip_timer_timeout();
    void on_update_timer_timeout();


};

#endif // VSCINTILLAEX_H
